<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户角色管理</title>
<link href="<c:url value='/insdep/reset.min.css' />" rel="stylesheet" type="text/css">
<link href="<c:url value='/insdep/easyui_full.css'/>" rel="stylesheet" type="text/css">
<link href="<c:url value='/insdep/icon.css'/>" rel="stylesheet" type="text/css">
<link href="<c:url value='/css/wsf-button.css'/>" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<c:url value='/insdep/jquery-1.11.3.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/insdep/jquery.easyui-1.5.2.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/insdep/insdep-extend.min.js'/>"></script>
<link rel="stylesheet" type="text/css" href="<c:url value='/insdep/iconfont/iconfont.css' />">
<link href="<c:url value='/css/wsf-button.css'/>" rel="stylesheet" type="text/css">
</head>
<body> 
<script type="text/javascript">
	$(function(){
		//重置
		$("#emp_role_reset").linkbutton({onClick:function(){
			$("#member_search_from").form("reset");
			$("#empinfo_dg").datagrid("load",{});
			
		}});
		//刷新
		$("#refresh_emp").linkbutton({onClick:function(){
			$("#empinfo_dg").datagrid("load",{});
			
		}});
		//分页将参数带过去
		$("#empinfo_dg").datagrid({
			onBeforeLoad:function(param){
				param.empname=$("input[name='serach_empname']").val();
			}
		});
		//搜索
		$("#emp_role_searcher").linkbutton({
			onClick:function(){
				
				$("#member_search_from").form('submit',{
					onSubmit:function(param){ 
				        param.page = '1';    
				        param.rows = '2'; 
					},
					success:function(data){
						alert(data);
						var resultdata=$.parseJSON(data);
						$("#empinfo_dg").datagrid('loadData', resultdata);
					}
				});
			}
		});
	});
	//性别格式化
	function formatter_sex(val) {
		return {0:"女", 1:"男"}[val];
	}
	/**
	 *保存指定的角色信息
	 */
	function save_empRole(index){
			//有时候把代码写在方法里面效果更好
			//先判断要关闭的是否是分配权限的窗口，是则提交
			var giveempid=$("#emp_role_win").window("options").empid;
			var checkednodes = $('#emprole_tree').tree('getChecked');
			var roleids = [];
			for (var i = 0; i < checkednodes.length; i++) {
				if(!checkednodes[i].children){
					roleids.push(checkednodes[i].id);
				}
			}
 			//提交表单
 			$("<form method='post'>").form({
 				url:'give_EmpRole',
 				onSubmit:function(params){
 					params.empid=giveempid;
 					params.roleids=roleids;
 				},
 				success:function(info){
		 			$("#emp_role_win").window('close');
					$("#empinfo_dg").datagrid("load");
 				}
 			}).submit();
	}
	//指定角色
	function appointRole(index){
    	$("#empinfo_dg").datagrid('selectRow',index);
     	var row = $("#empinfo_dg").datagrid('getSelected');  
			$("#emp_role_win").window({
		     width: 300,
	        height: 500,
	        title: '指定角色',
	        iconCls: 'icon-update',
	        modal: true,//表示模式窗口
	        maximizable:false,
	        minimizable:false,
	        collapsible:false,
	        draggable: true,
			href:'to_GiveEmpRole',//请求远程数据row.empid
			empid:row.empId
			});  
	}  
	function formatter_rolea_ction(val,row,index){
		var editrole="", removerole="";
		editrole = '<a class="button-teal iconfont icon-gonggao" style="color:white;padding:5px 7px;font-size:14px;margin-right:3%" >用户详情<a/>';
		removerole = '<a class="button-blue iconfont icon-profile" style="color:white;padding:5px 7px;font-size:14px;margin-right:3%" onclick="appointRole('+index+')">指定角色<a/>';
		return editrole+removerole;
	}
	
</script>
	<div class="easyui-layout" data-options="border:false" fit="true">
		<!--查询表单  --> 
    	<div data-options="region:'north',title:'用户管理',split:true,collapsed:true" style="padding:10px;height:100px;">
    		<form action="get_allEmp" id="member_search_from" class="searcher-form" method="post">
				<input name="empname" class="easyui-textbox field" label="用户名称："  labelWidth="70" style="width:300px">
    			<a id="emp_role_searcher" class="easyui-linkbutton" data-options="iconCls:'icon-search'">检索</a>
				<a id="emp_role_reset" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">重置</a>
    		</form>
    	</div> 
    
    
    <!--数据表格  --> 
    <div data-options="region:'center',border:false" style="border-top: 1px solid #D3D3D3">
		<table id="empinfo_dg" class="easyui-datagrid" 
		data-options="
		fit:true,
		fitColumns:true,
		url:'get_allEmp',
		rownumbers: true,
		toolbar: '#tb',
		nowrap:false, 
		autoRowHeight:true,
		autoRowWidth:300,
		pagination:true,
		pageSize: 2,
		pageList:[2,4,6,8]">
		<thead>
				<tr>
				<th style="width:10%" data-options="field:'empId', align:'center',sortable:true">员工编号</th>
				<th style="width:10%" data-options="field:'empName', align:'center'">员工名称</th>
				<th style="width:10%" data-options="field:'empSex', align:'center', formatter:formatter_sex">员工性别</th>
				<th style="width:10%" data-options="field:'positionName', align:'center'">员工职务</th>
				<th style="width:10%" data-options="field:'deptName', align:'center'">部门名称</th>
				<th style="width:32%" data-options="field:'menuroles', align:'center'">所属角色</th>
				<th style="width:19.8%" data-options="field:'empaction',  formatter:formatter_rolea_ction, align:'center'">操作</th>
				</tr>
		</thead>
		</table>
    </div>
    </div> 
    
    
    
    <!--easyui-datagrid当中的工具栏  -->
    <div id="tb">
    		<!-- <a id="create_emp" class="easyui-linkbutton" data-options="iconCls:'icon-add'">创建</a> -->
    		<a id="refresh_emp" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">刷新</a>
    </div>  
 
	<!--点击工具栏弹出window -->
	<div id="emp_role_win"></div>
</body> 
</html>